package com.yunxin.common.result;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * 分页响应结构体
 *
 * @author zero°
 * @since 2023-05-22
 */
@Data
public class PageResult<T> implements Serializable {

    /**
     * 异常code
     */
    private String code;
    /**
     * 异常信息
     */
    private String msg;
    /**
     * 数据
     */
    private Data<T> data;

    public static <T> PageResult<T> success(List<T> records, long total) {
        PageResult<T> result = new PageResult<>();
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setMsg(ResultCode.SUCCESS.getMsg());
        Data<T> data = new Data<>();
        data.setList(records);
        data.setTotal(total);
        result.setData(data);
        return result;
    }

    @lombok.Data
    public static class Data<T> implements Serializable {
        /**
         * 数据
         */
        private List<T> list;
        /**
         * 总条数
         */
        private long total;

    }

}
